package com.object.module.lq.chatroom.service.impl;

import cn.hutool.core.bean.copier.BeanCopier;
import cn.hutool.core.bean.copier.CopyOptions;
import com.alibaba.fastjson.JSON;
import com.object.module.lq.chatroom.service.NettyMsgService;
import com.object.utils.BeanCopierUtil;
import com.object.utils.NettyChantTypePojo;
import com.sun.corba.se.impl.copyobject.FallbackObjectCopierImpl;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import net.sf.cglib.proxy.Enhancer;
import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json;

import java.nio.file.OpenOption;
import java.util.Map;

/**
 * 简单的发送信息
 */
@Service("LNettyMsgSendServiceImpl")
public class LNettyMsgSendServiceImpl implements NettyMsgService
{
    @Override
    public void execute(ChannelHandlerContext context, NettyChantTypePojo nettyChantTypePojo)
    {
        Channel channel = getChannelByToken(nettyChantTypePojo.getMyToken());
        if (channel == null) {
            //发送的用户没有上线
            System.err.println("抱歉 该用户没有上线");
            System.out.println(JSON.toJSONString(nettyChantTypePojo));
            // TODO: 2023/7/25 需要把聊天记录存储到数据库  最好采用异步

            return;
        }
        sendTo(nettyChantTypePojo, channel);
    }

    public static void main(String[] args)
    {
        NettyChantTypePojo typePojo = new NettyChantTypePojo();
        typePojo.setType(100);
        NettyChantTypePojo typePojo1 = BeanCopierUtil.copyObject(typePojo);
        System.out.println(typePojo1);
    }

}
